﻿using System;
using System.Collections.Generic;
using System.Text;

using Weazel.Gezel.Model;

namespace Weazel.Gezel.Conversions
{
	/// <summary>
	/// Helper structure which maps connections between inports
	/// and outports in both directions.
	/// </summary>
	public class PortMap
	{
		private Dictionary<InPort,OutPort> inportMap;
		private Dictionary<OutPort, InPort> outportMap;

		public OutPort this[InPort inport]
		{
			get
			{
				if(inportMap.ContainsKey(inport))
					return inportMap[inport];
				else 
					throw new KeyNotFoundException(string.Format("could not find inport {0} in portmap", inport.Name));
			}
			set
			{
				inportMap[inport] = value;
			}
		}

		public InPort this[OutPort outport]
		{
			get
			{
				return outportMap[outport];
			}
			set
			{
				outportMap[outport] = value;
			}
		}

		public bool ContainsInport(InPort inport)
		{
			return inportMap.ContainsKey(inport);
		}

		public bool ContainsOutport(OutPort outport)
		{
			return outportMap.ContainsKey(outport);
		}

		public PortMap()
		{
			this.inportMap = new Dictionary<InPort, OutPort>();
			this.outportMap = new Dictionary<OutPort, InPort>();
		}
	}
}
